# Contributor: Ian Bashford <ianbashford@gmail.com>
# Maintainer: Ian Bashford <ianbashford@gmail.com>
pkgname=dnscrypt-proxy
pkgver=2.0.44
pkgrel=0
pkgdesc="Tool for securing communications between a client and a DNS resolver"
url="https://dnscrypt.info"
arch="all !mips64" # no golang on mips64
license="ISC"
depends="ca-certificates"
makedepends="libcap go"
install="$pkgname.pre-install"
pkgusers=dnscrypt
pkggroups=dnscrypt
subpackages="$pkgname-setup::noarch $pkgname-openrc"
source="$pkgname-$pkgver.tar.gz::https://github.com/DNSCrypt/dnscrypt-proxy/archive/$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	$pkgname.setup
	config-full-paths.patch
	"
options="!check"

prepare() {
	default_prepare
	ln -sf vendor src
}

build() {
	cd "$builddir"/"$pkgname"
	go build -ldflags="-s -w" -v
}

package() {
	cd "$builddir"/"$pkgname"
	install -d -o $pkgusers -g $pkggroups -m 755 "$pkgdir"/etc/$pkgname
	install -d -o $pkgusers -g $pkggroups -m 755 "$pkgdir"/usr/share/$pkgname
	install -d -o $pkgusers -g $pkggroups -m 755 "$pkgdir"/var/cache/$pkgname
	install -d -o $pkgusers -g $pkggroups -m 755 "$pkgdir"/var/log/$pkgname
	install -m755 -D dnscrypt-proxy "$pkgdir"/usr/bin/dnscrypt-proxy
	setcap cap_net_bind_service=+ep "$pkgdir"/usr/bin/dnscrypt-proxy
	install -vDm 644 "dnscrypt-proxy.toml" "$pkgdir/etc/$pkgname/dnscrypt-proxy.toml"
	install -m755 -D "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -m644 -D "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	for i in example-*;do install -m644 -D "$i" "$pkgdir"/usr/share/"$pkgname"/"$i"; done
}

setup() {
	pkgdesc="Script for setting up dnscrypt proxy"
	depends="sed wget $pkgname"

	install -m755 -D "$srcdir"/$pkgname.setup "$subpkgdir"/usr/sbin/setup-dnscrypt
}

sha512sums="009e2b669c1d6f6cd6b41f5e04d08735587f420dacdea8d422a3c12a62614c1ce1963deebca3af1f956070abd9ff5df9182cb27e31fa0fac8a95478739445801  dnscrypt-proxy-2.0.44.tar.gz
e0a72d39d47dc24b889d08beedbd9fdf21615f42fbab79980debdfd2c3feaa83dc3f776351f7dd13533cc85905ce4e01812e4ff8a80a9ccc0b21e9db7d6cb232  dnscrypt-proxy.initd
c001ae39da1b2db71764cab568f9ed18e4de0cea3d1a4e7bd6dd01a5668b81a888ea9eef99de6beac08857ad7f8eb1a32d730e946ac3563e4dcfa27147e35052  dnscrypt-proxy.confd
66dd43d84117a0151ae41f34d82b716760382a5a491424bf6418228ffd21f0dfbc88e34cc5074e11f97f006335d97b85367bb9ab1d96747a48e893c022ad52d0  dnscrypt-proxy.setup
5dd21a0da7dc339217044b862dc4ff7740f94f7b336d0b0ef8a02e9ed57d8303f89496c5740489aed98d901131efe31913ab1377fbc30197c1b5d2de0863666c  config-full-paths.patch"
